<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Request\Traits;

trait RetryTrait
{
    private $serverRetry = 0;
    private $serverRetryStrings = [];
    private $serverRetryStatusCodes = [];
    private $clientRetry = 0;
    private $clientRetryStrings = [];
    private $clientRetryStatusCodes = [];
    public function retryByServer($times, array $strings, array $statusCodes = [])
    {
        $this->serverRetry = \AlibabaCloud\Client\Filter\ClientFilter::retry($times);
        $this->serverRetryStrings = $strings;
        $this->serverRetryStatusCodes = $statusCodes;
        return $this;
    }
    public function retryByClient($times, array $strings, array $codes = [])
    {
        $this->clientRetry = \AlibabaCloud\Client\Filter\ClientFilter::retry($times);
        $this->clientRetryStrings = $strings;
        $this->clientRetryStatusCodes = $codes;
        return $this;
    }
    private function shouldServerRetry(\AlibabaCloud\Client\Result\Result $result)
    {
        if($this->serverRetry <= 0) {
            return false;
        }
        if(in_array($result->getStatusCode(), $this->serverRetryStatusCodes)) {
            $this->serverRetry--;
            return true;
        }
        foreach ($this->serverRetryStrings as $message) {
            if(\Stringy\Stringy::create($result->getBody())->contains($message)) {
                $this->serverRetry--;
                return true;
            }
        }
        return false;
    }
    private function shouldClientRetry(\Exception $exception)
    {
        if($this->clientRetry <= 0) {
            return false;
        }
        if(in_array($exception->getCode(), $this->clientRetryStatusCodes, true)) {
            $this->clientRetry--;
            return true;
        }
        foreach ($this->clientRetryStrings as $message) {
            if(\Stringy\Stringy::create($exception->getMessage())->contains($message)) {
                $this->clientRetry--;
                return true;
            }
        }
        return false;
    }
}

?>